package com.guoxin.principle.single;

/**
 * 单一职责原则
 *
 * @author guoxin
 * @date 2019/8/14
 */
public class SingleResponsibility2 {

    public static void main(String[] args) {
        RoadVehicle rv = new RoadVehicle();
        rv.run("摩托车");
        rv.run("汽车");

        AirVehicle av = new AirVehicle();
        av.run("飞机");
    }

    /**
     * 方案2的分析
     * 1.遵守了单一职责原则
     * 2.但是这样的改动很大，即将类分解，同时修改客户端
     * 3.改进：直接将Vehicle嘞，给懂的代码比较少=》方案3
     */
    private static class RoadVehicle {
        public void run(String vehicle) {
            System.out.println(vehicle + ",在公路上行驶...");
        }
    }


    private static class AirVehicle {
        public void run(String vehicle) {
            System.out.println(vehicle + ",在天空中行驶...");
        }
    }

}

